//
//  ETH.swift
//  XHWalletUtils
//
//  Created by xinph on 2020/5/16.
//  Copyright © 2020 xinph. All rights reserved.
//

import Foundation
@_exported import web3swift
@_exported import BigInt
@_exported import PromiseKit

public class ETH: Wallet {
    static var web3: web3?
    public var ethKeystore: BIP32Keystore?

    override public class func empty() -> WalletType {
        return ETH(keystore: Data(), path: CoinBIP44.defaultETHPath, isHD: false, privateKey: nil, publicKey: nil)
    }
    
    override init(_ mnemonic: String? = nil, keystore: Data?, path: String, isHD: Bool, privateKey: String?, publicKey: String?) {
        super.init(mnemonic, keystore: keystore, path: path, isHD: isHD, privateKey: privateKey, publicKey: publicKey)
        didLoad()
        purpose = 44
        coinType = 60
    }
    
    required init(from decoder: Decoder) throws {
        try super.init(from: decoder)
    }
    
    override public func didLoad() {
        ETH.setCipher(password: zxbcmbaksd)
        if isHDWallet {
//            if self.ethKeystore == nil {
//                /// 加载keystore
//                self.ethKeystore = BIP32Keystore(self.keystore!)
//            }
            _ = generateWeb3()
            /// 加载keystore内部子账户
            createSevralAccounts(Manager.shared.password ?? "", need: UInt64(self.accounts.count))
        }
    }
}
